A Catch
clause that only rethrows the caught exception has the same effect as omitting the Catch
altogether and letting
it bubble up automatically.
Dim s As String = ""
Try
s = File.ReadAllText(fileName)
Catch e As Exception
Throw
End Try
Such clauses should either be removed or populated with the appropriate logic.
Dim s As String = File.ReadAllText(fileName)
or
Dim s As String = ""
Try
s = File.ReadAllText(fileName)
Catch e As Exception
logger.LogError(e)
Throw
End Try
Exceptions
This rule will not generate issues for Catch
blocks if they are followed by a Catch
block for a more general exception
type that does more than just rethrowing the exception.
Dim s As String = ""
Try
s = File.ReadAllText(fileName)
Catch e As IOException 'Compliant by exception: removing it would change the logic
Throw
Catch e As Exception 'Compliant: does more than just rethrow
logger.LogError(e)
Throw
End Try